package com.forotuxpan.appforotuxpan;

import android.app.Fragment;
import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

public class ItemAdapterABC extends ArrayAdapter<Row>
{
    private LayoutInflater layoutInflater;
    private final Context context;
    private final List<Row> list;

    public ItemAdapterABC(Context context, List<Row> objects)
    {
        super(context, R.layout.listview_row, objects);
        layoutInflater = LayoutInflater.from(context);
        this.context = context;
        this.list = objects;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        // holder pattern
        Holder holder = null;
        if (convertView == null)
        {
            holder = new Holder();

            convertView = layoutInflater.inflate(R.layout.listview_row, null);
            holder.setTextViewTitle((TextView) convertView.findViewById(R.id.textViewTitle));

            ImageView ivItem = (ImageView) convertView.findViewById(R.id.ivItem);
            ivItem.setImageResource(R.drawable.ic_image_navigate_next);

            convertView.setTag(holder);
            convertView.setTag(R.id.textViewTitle, holder.getTextViewTitle());
        }
        else
        {
            holder = (Holder) convertView.getTag();
        }

        final Row row = getItem(position);
        holder.getTextViewTitle().setText(row.getTitle());

        return convertView;
    }

}
